import { defineStore } from "pinia";
import { reqgetHouseInfos } from "../../services/modules/detail.js"

const useDeatilStore = defineStore("detail", {
    state: () => {
        return{
            mainPart: {},
            housePics: [],   //轮播图片
        }
    },
    actions: {
        async getHouseInfos(houseId){
            const res = await reqgetHouseInfos(houseId)
            console.log("res", res.data)
            if(res.data){
                this.mainPart = res.data.mainPart
                this.housePics = res.data.mainPart.topModule.housePicture.housePics
            }
        }
    },
    getters: {
        // housePics: state => state.mainPart.topModule?.housePicture?.housePics,
        swipeGroup: state => {
            const swipeGroup = {}
            for ( const item of state.housePics){
                let valueArray = swipeGroup[item.enumPictureCategory]
                if(!valueArray){    //第一次遍历是undefined
                    valueArray = []
                    swipeGroup[item.enumPictureCategory] = valueArray
                }
                valueArray.push(item)
            }
            return swipeGroup
        }
    },
})

export default useDeatilStore